const vm = new Vue({
    el: "#houtai",
    data: {
        start: 1,
        end: 1,
        tableData: [],
        drawer: false,   // 文章详情页面
        aid: "", // 文章id
        // 文章详情
        article: {
            "title": "",
            "content": "",
            "zhaiyao": "",
            "tags": "",
            "writer": {
                "nickname": "",
                "img": ""
            }
        },
        tags: ['旅游', '音乐', '编程', '美食', "情感", "体育", "摸鱼", "健康", "摄影", "校园", "娱乐", "其它"],   // 分类
    },
    created() {
        this.start = 1;
        this.getData()
    },
    methods: {
        exit_() {
            const uid = sessionStorage.getItem("user_id");
            if (uid) {
                sessionStorage.removeItem("user_id");   //删除session
            }
            window.location.href = "/";
            axios({
                url: "/user/exit",
                method: "get",
                params: {
                    "uid": uid
                }
            })
        },
        // 审核确认
        shenHe(n) {
            let msg = "";
            if (n === 1) {
                msg = "当前操作：审核通过!"

            } else if (n === -1) {
                msg = "当前操作：审核不通过！"
            }
            this.$alert(msg, "二次确认", {
                confirmButtonText: "确定",
                callback: action => {
                    axios({
                        url: "/article/dosh/" + this.aid + "/" + n,
                        method: "get"
                    }).then(
                        (resp) => {
                            if (resp.data.statu) {
                                this.$message.success("审核成功!")
                                this.start = 1;
                                this.getData()

                            } else {
                                this.$message.error(resp.data.reason);
                            }
                        }
                    )
                    this.drawer = false;
                }
            })
        },
        // 查看详情
        openArt(aid) {
            this.aid = aid;
            this.drawer = true;
            axios({
                url: "/article/xq_admin/" + aid,
                method: "get"
            }).then(
                (resp) => {
                    if (resp.data.statu) {
                        this.article = resp.data.datas
                    }
                }
            )
        },
        // 关闭详情确认
        handleClose(done) {
            this.$confirm('确认关闭？')
                .then(_ => {
                    done();
                })
                .catch(_ => {
                });
        },
        to_map() {
            window.location.href = "/admin_map";
        },
        change(val) {
            this.start = val;
            this.getData();
        },
        next() {
            if (this.start < this.end) {
                this.start++;
                this.getData();
            }
        },
        last() {
            if (this.start > 1) {
                this.start--;
                this.getData();
            }
        },
        getData() {
            axios({
                url: "/article/shenhe/" + this.start,
                method: "get"
            }).then(
                (resp) => {
                    if (resp.data.statu) {
                        this.tableData = resp.data.datas;
                        if (this.start === 1) {
                            this.end = resp.data.pageNum
                        }
                    }
                }
            )
        },
    }

})